<?php
use backend\assets\BackendAsset;
use backend\widgets\Menu;
use common\models\TimelineEvent;

use yii\helpers\Url;

$bundle = BackendAsset::register($this);
?>

<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
        <!-- sidebar menu: : style can be found in sidebar.less -->

        <?php
        use mdm\admin\components\MenuHelper;
        $callback = function($menu){
            $data = json_decode($menu['data'], true);
            $items = $menu['children'];
            $return = ['label' => $menu['name'],'url' => [$menu['route']]];

            if(isset($data['class']) && isset($data['class']) == 'header'){
                $return = ['label' => $menu['name']];
            }
            //处理我们的配置
            if ($data) {
                isset($data['visible']) && $return['visible'] = $data['visible'];//visible
                isset($data['icon']) &&  $return['icon'] = $data['icon'];//icon
                //other attribute e.g. class...
                $return['options'] = $data;
            }
            //如果class = header 则显示文字;
            //没配置图标的显示默认图标
            (!isset($return['icon']) || !$return['icon']) && $return['icon'] = 'fa fa-lock';
            $items && $return['items'] = $items;
            return $return;
        };

        //这里我们对一开始写的菜单menu进行了优化
        echo mdm\admin\widgets\Menu::widget( [
            'options' => ['class' => 'sidebar-menu'],
            'items' => MenuHelper::getAssignedMenu(Yii::$app->user->id,null, $callback),
        ] );

        ?>

        <?php
//        echo Menu::widget([
//            'options'=>['class'=>'sidebar-menu'],
//            'linkTemplate' => '<a href="{url}">{icon}<span>{label}</span>{right-icon}{badge}</a>',
//            'submenuTemplate'=>"\n<ul class=\"treeview-menu\">\n{items}\n</ul>\n",
//            'activateParents'=>true,
//            'items'=>[
//
//                [
//                    'label'=>'日志&缓存',
//                    'options' => ['class' => 'header']
//                ],
//                [
//                    'label'=>'日志&缓存',
//                    'url' => '#',
//                    'icon'=>'<i class="fa fa-cogs"></i>',
//                    'options'=>['class'=>'treeview'],
//                    'items'=>[
//                        [
//                            'label'=>Yii::t('backend', 'i18n'),
//                            'url' => '#',
//                            'icon'=>'<i class="fa fa-flag"></i>',
//                            'options'=>['class'=>'treeview'],
//                            'items'=>[
//                                ['label'=>Yii::t('backend', 'i18n Source Message'), 'url'=>['/i18n/i18n-source-message/index'], 'icon'=>'<i class="fa fa-angle-double-right"></i>'],
//                                ['label'=>Yii::t('backend', 'i18n Message'), 'url'=>['/i18n/i18n-message/index'], 'icon'=>'<i class="fa fa-angle-double-right"></i>'],
//                            ]
//                        ],
//                        ['label'=>Yii::t('backend', 'Key-Value Storage'), 'url'=>['/key-storage/index'], 'icon'=>'<i class="fa fa-angle-double-right"></i>'],
//                        ['label'=>Yii::t('backend', 'File Storage'), 'url'=>['/file-storage/index'], 'icon'=>'<i class="fa fa-angle-double-right"></i>'],
//                        ['label'=>Yii::t('backend', 'Cache'), 'url'=>['/cache/index'], 'icon'=>'<i class="fa fa-angle-double-right"></i>'],
//                        ['label'=>Yii::t('backend', 'File Manager'), 'url'=>['/file-manager/index'], 'icon'=>'<i class="fa fa-angle-double-right"></i>'],
//                        [
//                            'label'=>Yii::t('backend', 'System Information'),
//                            'url'=>['/system-information/index'],
//                            'icon'=>'<i class="fa fa-angle-double-right"></i>'
//                        ],
//                        [
//                            'label'=>Yii::t('backend', 'Logs'),
//                            'url'=>['/log/index'],
//                            'icon'=>'<i class="fa fa-angle-double-right"></i>',
//                            'badge'=>\backend\models\SystemLog::find()->count(),
//                            'badgeBgClass'=>'label-danger',
//                        ],
//                    ]
//                ]
//            ]
//        ]) ?>

    </section>
</aside>
